package cn.gzsxt.music.controller;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.gzsxt.music.query.PowerQueryObject;
import cn.gzsxt.music.service.PowerService;
import cn.gzsxt.music.vo.MsgObj;

@Controller
@Scope("request")
@RequestMapping("/power")
public class PowerController {

	@Autowired
	private PowerService service;
	
	@RequestMapping("powerPage")
	public String modularPage() {
		
		return "powerPage";
	}
	
	@RequestMapping("powerList")
	@ResponseBody
	public Map<String, Object> modularList(PowerQueryObject qo) {
		System.out.println(qo);
		Map<String, Object> result = service.selectPowerDataByCondition(qo);
		return result;
	}
	
	@RequestMapping("addPower")
	@ResponseBody
	public MsgObj addPower(@RequestParam Map<String, Object> params) {
		
		int row = service.savePower(params);
		
		MsgObj msgObj = new MsgObj(0, "添加权限失败");
		if(row == 1) {
			msgObj = new MsgObj(1, "添加权限成功");
		}else if(row == 2) {
			msgObj = new MsgObj(0, "此权限路径已经存在");
		}
		return msgObj;
	}
	
	@RequestMapping("updatePower")
	@ResponseBody
	public MsgObj updatePower(@RequestParam Map<String, Object> params) {
		
		int row = service.updatePower(params);
		
		MsgObj msgObj = new MsgObj(0, "修改权限失败");
		if(row == 1) {
			msgObj = new MsgObj(1, "修改权限成功");
		}else if(row == 2) {
			msgObj = new MsgObj(0, "此权限路径已经存在");
		}
		return msgObj;
	}
	
	@RequestMapping("deletePowerById")
	@ResponseBody
	public MsgObj deleteModularById(Long power_id) {
		
		int row = service.deletePowerById(power_id);
		
		MsgObj msgObj = new MsgObj(0, "删除权限失败");
		if(row == 1) {
			msgObj = new MsgObj(1, "删除权限成功");
		}
		return msgObj;
	}
	
	
}
